home *** CD-ROM | disk | FTP | other *** search
- #include <stdlib.h>
- #include <errno.h>
-
- #include <proto/exec.h>
-
- #if defined(__SASC_510)
- void *LibCreatePool(ULONG, ULONG, ULONG);
- void *LibAllocPooled(void *, ULONG);
- void LibDeletePool(void *);
- #else
- #include <clib/alib_protos.h>
- #endif
-
- #include "Internal.h"
-
- /*************************************************************************/
-
- void *__MemoryPool;
-
- /*************************************************************************/
-
- void *malloc(size_t Size)
-
- {
- unsigned long *Memory;
-
- /* create memory pool if necessary */
- if (!__MemoryPool)
- {
- if ((__MemoryPool=LibCreatePool(0,64*1024,32*1024)))
- {
- MemoryCleanup=LibDeletePool;
- }
- else
- {
- errno=ENOMEM;
- return NULL;
- }
- }
-
- /* do the allocation */
- Size=(Size+sizeof(*Memory)+4-1)&~3; /* make sure size is longword multiple */
- if ((Memory=LibAllocPooled(__MemoryPool,Size)))
- {
- *(Memory++)=Size;
- }
- else
- {
- errno=ENOMEM;
- }
- return Memory;
- }
-